package net.sansi.v3correctserver.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import net.sansi.v3correctserver.dto.R;
import net.sansi.v3correctserver.dto.v3serverapi.V3ServerApiScreenDto;
import net.sansi.v3correctserver.service.v3serverapi.V3ServerScreenApi;
import net.sansi.v3correctserver.service.websocket.updateprogress.UpdateProgressWSManager;
import net.sansi.v3correctserver.task.RequestAttributeTestTask;
import net.sansi.v3correctserver.util.CmmUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by Fang
 * create time : 2024/11/1
 * IDE : IntelliJ IDEA
 */

@Api(tags = "测试接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private V3ServerScreenApi v3ServerScreenApi;

    @ApiOperation("forest 测试")
    @GetMapping("/forest")
    public R<V3ServerApiScreenDto.ScreensResp> forest() {
        return R.data(v3ServerScreenApi.screens(100, 0));
    }


    // websocket 测试
    @ApiOperation("websocket 推送测试")
    @GetMapping("/ws/task/update/progress")
    public R<String> websocket(String message) {
        UpdateProgressWSManager.getInstance().sendMessage(message);
        return R.data("success");
    }

    // task 测试
    @SneakyThrows
    @ApiOperation("task 测试异步任务Request传递")
    @GetMapping("/task/requestAttribute")
    public R<String> taskTestRequestAttribute() {
        CmmUtil.setRequestAttribute("t1", "tt1");
        RequestAttributeTestTask task = new RequestAttributeTestTask(null);
        task.start();
        return R.data(task.getTaskId());
    }


}
